home *** CD-ROM | disk | FTP | other *** search
/ Hottest 6 / Hottest 6 (1996)(PDSoft)[!].iso / utilities / iconian / sources / gaugeimage.e < prev    next >
Text File  |  1978-11-24  |  8KB  |  259 lines

  1. /*  gaugeimage.class  PublicDomain by Chad Randall  */
  2.  
  3. OPT PREPROCESS
  4. LIBRARY 'gaugeimage.class',1,1,'gaugeiclass 1.0 (18.8.95)' IS init_gaugeiclass,free_gaugeiclass
  5.  
  6. MODULE    'class/gaugeimage'
  7.  
  8. MODULE    'amigalib/boopsi'
  9. MODULE    'exec/memory','exec/types'
  10. MODULE    'graphics/gfxbase','graphics/scale','graphics/gfx','graphics/rastport',
  11.                 'graphics/view','graphics/text'
  12. MODULE    'intuition/classes','intuition/imageclass','intuition/cghooks','intuition/classusr',
  13.                 'intuition/screens','intuition/intuition','intuition/gadgetclass'
  14. MODULE    'tools/installhook'
  15. MODULE    'utility','utility/tagitem'
  16. MODULE    'gadtools','libraries/gadtools'
  17.  
  18. MODULE    'mod/gadgets'
  19. MODULE    'mod/fonts'
  20. MODULE    'mod/compare'
  21.  
  22. OBJECT gaugeidata
  23.     screen:PTR TO screen
  24.     bottom:LONG
  25.     top:LONG
  26.     curlevel:LONG
  27.     textfont:PTR TO textfont
  28.     textstyle:LONG
  29.     lastx:LONG
  30.     type:LONG
  31.     debug:LONG
  32.     lasttop:LONG
  33.     lastbottom:LONG
  34.     lastlevel:LONG
  35. ENDOBJECT
  36.  
  37.  
  38. PROC gaugeim_new(cl:PTR TO iclass,obj:PTR TO object,msg:PTR TO opset)
  39.     DEF    data:PTR TO gaugeidata
  40.     DEF textstring=0
  41.     DEF dri=0:PTR TO drawinfo
  42.     DEF fti
  43.     data:=INST_DATA(cl, obj)
  44.  
  45. ->data.debug:=Open('CON:',NEWFILE)
  46. ->stdout:=data.debug
  47.     data.screen:=GetTagData(GAUGEIA_SCREEN,NIL,msg.attrlist)
  48.     IF data.screen=0
  49.         RETURN -1
  50.     ELSE
  51.         data.bottom:=GetTagData(GAUGEIA_BOTTOM,NIL,msg.attrlist)
  52.         data.top:=GetTagData(GAUGEIA_TOP,100,msg.attrlist)
  53.         data.curlevel:=GetTagData(GAUGEIA_CURLEVEL,50,msg.attrlist)
  54.         data.type:=GetTagData(GAUGEIA_STYLE,NIL,msg.attrlist)
  55.         data.textfont:=GetTagData(GAUGEIA_TEXTFONT,NIL,msg.attrlist)
  56.         data.textstyle:=GetTagData(GAUGEIA_TEXTSTYLE,NIL,msg.attrlist)
  57.     ENDIF
  58. ENDPROC
  59.  
  60. PROC gaugeim_dispose(cl:PTR TO iclass,obj:PTR TO object)
  61.     DEF data:PTR TO gaugeidata
  62.     data:=INST_DATA(cl, obj)
  63. ->    IF data.debug THEN Close(data.debug)
  64. ENDPROC
  65.  
  66. PROC gaugeim_get(cl:PTR TO iclass,obj:PTR TO object,msg:PTR TO opget)
  67.     DEF data:PTR TO gaugeidata
  68.     DEF retval=TRUE
  69.     DEF switch
  70.     data:=INST_DATA(cl, obj)
  71.     switch:=msg.attrid
  72.     SELECT switch
  73.     CASE GAUGEIA_SCREEN;msg.storage:=data.screen
  74.     CASE GAUGEIA_BOTTOM;msg.storage:=data.bottom
  75.     CASE GAUGEIA_TOP;msg.storage:=data.top
  76.     CASE GAUGEIA_CURLEVEL;msg.storage:=data.curlevel
  77.     CASE GAUGEIA_STYLE;msg.storage:=data.type
  78.     CASE GAUGEIA_TEXTFONT;msg.storage:=data.textfont
  79.     CASE GAUGEIA_TEXTSTYLE;msg.storage:=data.textstyle
  80.     DEFAULT;retval:=doSuperMethodA(cl,obj,msg)
  81.     ENDSELECT
  82. ENDPROC retval
  83.  
  84. PROC gaugeim_set(cl:PTR TO iclass,obj:PTR TO object,msg:PTR TO opset)
  85.     DEF data:PTR TO gaugeidata
  86.     DEF ti:PTR TO tagitem
  87.     DEF tstate:PTR TO tagitem
  88.     DEF switch
  89.     DEF update=FALSE
  90.  
  91.     tstate:=msg.attrlist
  92.     data:=INST_DATA(cl, obj)
  93.  
  94.     WHILE (ti:=NextTagItem({tstate}))
  95.         switch:=ti.tag
  96.         SELECT switch
  97.         CASE GAUGEIA_BOTTOM;data.bottom:=ti.data
  98.         CASE GAUGEIA_TOP;data.top:=ti.data
  99.         CASE GAUGEIA_CURLEVEL;data.curlevel:=ti.data
  100.         CASE GAUGEIA_STYLE;data.type:=ti.data
  101.         CASE GAUGEIA_TEXTFONT;data.textfont:=ti.data
  102.         CASE GAUGEIA_TEXTSTYLE;data.textstyle:=ti.data
  103.         ENDSELECT
  104.     ENDWHILE
  105. ENDPROC
  106.  
  107. PROC gaugeim_draw(cl:PTR TO iclass,obj:PTR TO object,msg:PTR TO impdraw)
  108.     DEF data:PTR TO gaugeidata
  109.     DEF left,top,width,height
  110.     DEF switch
  111.     DEF    bsa:PTR TO bitscaleargs
  112.   DEF    temp_rp:PTR TO rastport
  113.     DEF visual
  114.     DEF drawinfo:PTR TO drawinfo
  115.     DEF newx
  116.     DEF w,h,i
  117.     DEF quant,max,bottom,textfont
  118.     DEF string
  119.     DEF drawtext=TRUE,drawlevel=TRUE
  120.  
  121.     data:=INST_DATA(cl, obj)
  122.     switch:=msg.state
  123.     SELECT switch
  124.     CASE IDS_SELECTED;drawtext:=FALSE
  125.     CASE IDS_INACTIVENORMAL;drawlevel:=FALSE
  126.     ENDSELECT
  127.  
  128.     IF data.screen
  129.         visual:=GetVisualInfoA(data.screen,NIL)
  130.         drawinfo:=msg.drinfo
  131.         IF drawinfo=0 THEN drawinfo:=GetScreenDrawInfo(data.screen)
  132.         GetAttr(IA_LEFT,obj,{left})
  133.         GetAttr(IA_TOP,obj,{top})
  134.         left:=left+msg.offsetx
  135.         top:=top+msg.offsety
  136.         IF (msg.methodid=IM_DRAWFRAME)
  137.             width:=msg.dimensionswidth
  138.             height:=msg.dimensionsheight
  139.         ELSE
  140.             GetAttr(IA_WIDTH,obj,{width})
  141.             GetAttr(IA_HEIGHT,obj,{height})
  142.         ENDIF
  143.         GetAttr(IA_DATA,obj,{string})
  144.         bottom:=data.bottom
  145.         max:=data.top
  146.         quant:=data.curlevel
  147.         IF ((max-bottom)>0)
  148.             newx:=(((width-7)*100)/(10000/(bigger((quant*100/(max)),1))))
  149.             IF ((newx<data.lastx) OR (data.top<>data.lasttop) OR (data.bottom<>data.lastbottom) OR (data.curlevel<data.lastlevel))
  150.                 drawbevelbox(visual,msg.rport,left,top,width,height,1,TRUE,0)
  151.                 data.lastx:=0
  152.             ENDIF
  153.             IF data.lastx=-1 THEN data.lastx:=0
  154.             SetDrMd(msg.rport,RP_JAM2)
  155.             SetAPen(msg.rport,drawinfo.pens[FILLPEN])
  156.             IF (drawlevel)
  157.                 RectFill(msg.rport,left+data.lastx+3,top+2,left+newx+3,top+height-3)
  158.                 IF data.type=GAUGETYPE_FANCY
  159.                     qwikbox(visual,msg.rport,left,top,width,height,2,1,4)
  160.                     qwikbox(visual,msg.rport,left,top,width,height,4,1,3)
  161.                     qwikbox(visual,msg.rport,left,top,width,height,4,3,3)
  162.                     qwikbox(visual,msg.rport,left,top,width,height,8,1,2)
  163.                     qwikbox(visual,msg.rport,left,top,width,height,8,3,2)
  164.                     qwikbox(visual,msg.rport,left,top,width,height,8,5,2)
  165.                     qwikbox(visual,msg.rport,left,top,width,height,8,7,2)
  166.                 ENDIF
  167.             ENDIF
  168.         ENDIF
  169.         IF (drawtext)
  170.             IF (string)
  171.                 IF (drawlevel=FALSE)
  172.                     drawbevelbox(visual,msg.rport,left,top,width,height,1,TRUE,0)
  173.                     data.lastx:=-1
  174.                 ENDIF
  175.                 w,h:=fontsize2(msg.rport,string,data.textfont,data.textstyle)
  176.                 SetFont(msg.rport,data.textfont)
  177.                 SetDrMd(msg.rport,RP_JAM1)
  178.                 Move(msg.rport,left+((width)/2)-(w/2),top+data.textfont.baseline+1)
  179.                 SetAPen(msg.rport,drawinfo.pens[TEXTPEN])
  180.                 Text(msg.rport,string,StrLen(string))
  181.             ENDIF
  182.         ENDIF
  183.         data.lastx:=newx
  184.         data.lasttop:=data.top
  185.         data.lastbottom:=data.bottom
  186.         data.lastlevel:=data.curlevel
  187.         IF msg.drinfo=0 THEN FreeScreenDrawInfo(data.screen,drawinfo)
  188.         FreeVisualInfo(visual)
  189.     ELSE
  190.         DisplayBeep(0)
  191.     ENDIF
  192. ENDPROC
  193.  
  194. PROC gaugeim_hitframe(cl:PTR TO iclass,obj:PTR TO object,msg:PTR TO imphittest)
  195.     DEF left,top
  196.  
  197.     GetAttr(IA_LEFT,obj,{left})
  198.     GetAttr(IA_TOP,obj,{top})
  199.     RETURN (msg.pointx>=left AND msg.pointy>=top AND msg.pointx<(left+msg.dimensionswidth) AND msg.pointy<(left+msg.dimensionsheight))
  200. ENDPROC
  201.  
  202. PROC gaugeim_eraseframe(cl:PTR TO iclass,obj:PTR TO object,msg:PTR TO imperase)
  203.     DEF left,top
  204.  
  205.     GetAttr(IA_LEFT,obj,{left})
  206.     GetAttr(IA_TOP,obj,{top})
  207.     left:=left+msg.offsetx
  208.     top:=top+msg.offsety
  209.     EraseRect(msg.rport,left,top,left+msg.dimensionswidth-1,top+msg.dimensionsheight-1)
  210. ENDPROC
  211.  
  212. PROC gaugei_dispatcher(cl:PTR TO iclass,obj:PTR TO object,msg:PTR TO msg)
  213.     DEF retval=0
  214.     DEF switch
  215.  
  216.     IF (utilitybase=0) THEN utilitybase:=OpenLibrary('utility.library',37)
  217.     IF (gadtoolsbase=0) THEN gadtoolsbase:=OpenLibrary('gadtools.library',37)
  218.  
  219.     switch:=msg.methodid
  220.     SELECT switch
  221.     CASE OM_NEW
  222.         retval:=doSuperMethodA(cl,obj,msg)
  223.         IF retval THEN gaugeim_new(cl,retval,msg)
  224.     CASE OM_DISPOSE
  225.         gaugeim_dispose(cl,obj)
  226.         retval:=doSuperMethodA(cl,obj,msg)
  227.         CloseLibrary(utilitybase)
  228.         utilitybase:=0
  229.     CASE OM_GET;retval:=gaugeim_get(cl,obj,msg)
  230.     CASE OM_SET
  231.         retval:=1
  232.         doSuperMethodA(cl,obj,msg)
  233.         gaugeim_set(cl,obj,msg)
  234.     CASE IM_DRAW;gaugeim_draw(cl,obj,msg)
  235.     CASE IM_DRAWFRAME;gaugeim_draw(cl,obj,msg)
  236.     CASE IM_HITFRAME;retval:=gaugeim_hitframe(cl,obj,msg)
  237.     CASE IM_ERASEFRAME;gaugeim_eraseframe(cl,obj,msg)
  238.     DEFAULT;retval:=doSuperMethodA(cl,obj,msg)
  239.     ENDSELECT
  240. ENDPROC retval
  241.  
  242. PROC init_gaugeiclass()
  243.     DEF cl:PTR TO iclass
  244.     IF cl:=MakeClass('gaugeiclass','imageclass',NIL,SIZEOF gaugeidata,0)
  245.         installhook(cl.dispatcher,{gaugei_dispatcher})
  246.     ENDIF
  247. ENDPROC cl
  248.  
  249. PROC free_gaugeiclass(cl) IS FreeClass(cl)
  250.  
  251. PROC main() IS EMPTY
  252.  
  253. PROC qwikbox(visual,rast,x,y,w,h,div,mul,height)
  254.     drawbevelbox(visual,rast,x+((((w*100)/(div))*mul)/100),y+h-height-1,2,height,0)
  255. ENDPROC
  256.  
  257. ver:
  258. CHAR 0,0,'$VER: guageimage.class 1.0 (11.9.95)',0,0
  259.